$(function() {
	var ctxPath =$('body').attr('ctxPath');
	var basicInfoId = $('#id').val();
	// 导航菜单选择后变换样式
	$('#myInfoTab').tab({
		defaultIndex : 0,
		activeClass : "tab-blue"
	});
	
	// 点击个人资料后隐藏其它页面
	$('#myInfo').on('click',function() {
		$("#myInfoDiv").show().siblings().hide();
	});
	
	// 点击更多信息隐藏其它页面
	$('#moreInfo').on('click',function() {
		var id = $('#id').val();
		var url = ctxPath +'/basic/my/extra/'+id+'?_t='+new Date().getTime();
		var div = $('#extraInfo');
		div.empty();
		$.ajax({
			type:'post',
			url:url,
			dataType:'json',
			success:function(data){
				if(data.flag){
					for(var i in data.info){
						div.append('<p><label class="weui-form-preview-label">'+i+'</label><span class="weui-form-preview-value">'+data.info[i]+'</span></p>');
					}
				}else{
					div.append('<p class="p_center">'+data.info+'</p>');
				}
			},
			error:function(error){
				console.log(error);
				$.toptips("网络开小差了:(");
			}
		});
		$("#moreInfoDiv").show().siblings().hide();
	});
	
	// 点击个人风采后隐藏其它页面
	$('#aboutInfo').on('click',function() {
		//获取个人风采
		$("#myAboutInfo").empty();
		var div = $("#myAboutInfo");
		$.ajax({
			type:'post',
			url:ctxPath+'/basic/detail/about/view/'+basicInfoId+'?_t='+new Date().getTime(),
			dataType:'json',
			success:function(data){
				if(data.flag){
					$(data.list).each(function(index,obj){
						console.log(obj.textContext);
						$(obj.listUrl).each(function(i,ele){
							console.log(ele);
							div.append('<div class="weui-weixin-img"><img src="'+ele+'"></div>');
						})
						div.append('<p class="weui_media_desc">'+obj.textContext+'</p>');
						
					})
				}else{
					console.log(data.msg);
					div.append('<p class="p_center">'+data.msg+'</p>');
				}
			},
			error:function(error){
				$.alert("网络开小差了:(");
			}
		});
		$("#aboutDiv").show().siblings().hide();
	});
	
	//跳转到添加个人风采
	$('#addAboutInfo').on('click',function(){
		window.location.href= ctxPath +'/basic/detail/about/add/'+basicInfoId+'?_t='+new Date().getTime();
	})
	
	
	$('#btnEnsure').on('click',function(){
		var url = ctxPath+'/basic/my/detail/about/save?_t='+new Date().getTime();
		$("#basicInfoId").val(basicInfoId);//基本信息ID
		var params = $("#form").serialize();
		$.ajax({
			type:'POST',
			url:url,
			data:params,
			dataType:'json',
			success:function(data){
				console.log(data);
				if(data.flag){
					console.log(data.msg);
					$('#model').hide();
				}else{
					$.toptips(data.msg);
					return;
				}
			},
			error:function(error){
				$.toptips("网络开小差了:(","提示");
				return;
			}
		});
	})
	

})